﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using Lamex.Library;
using DevExpress.XtraCharts;
using Lamex.Interface;
using System.Collections;

namespace Lamex.mMES.UI
{
    public partial class frmMES_Lab_ChartControl : frmBaseChild
    {

        #region 参考资料

        //DevExpress控件使用之多重坐标图形的绘制 
        //https://www.cnblogs.com/wuhuacong/archive/2013/05/13/3076142.html

        //Dev中ChartControl——属性熟悉与简单应用
        //https://www.seotest.cn/jishu/46624.html

        //DevExpress chartControl 基本结构说明
        //https://blog.csdn.net/weixin_43862847/java/article/details/104941514
        //XYDiagram diagram = chartControl1.Diagram as XYDiagram;
        ////wholeRange必须大于VisualRange,
        ////当VisualRange小于wholeRange时说明当前chart处于缩放状态，显示了部分刻度
        //// 整个range最大值最小值
        //diagram.AxisX.WholeRange.MinValue = 500;
        //diagram.AxisX.WholeRange.MaxValue = 2000;
        //// 一起设置
        //diagram.AxisX.WholeRange.SetMinMaxValues(500, 2000);

        //// range可视化最大值最小值
        //diagram.AxisX.VisualRange.MinValue = 1000;
        //diagram.AxisX.VisualRange.MaxValue = 1500;
        ////一起设置.
        //diagram.AxisX.VisualRange.SetMinMaxValues(1000, 1500);
        ////x轴刻度类型，共三类，Automatic：自动聚合  ，manual：根据手动设置ScaleOptions里的measureUnit聚合， Continuous：不聚合
        //Diagram1.AxisX.NumericScaleOptions.ScaleMode = DevExpress.XtraCharts.ScaleMode.Automatic;
        //Diagram1.AxisX.NumericScaleOptions.MeasureUnit = NumericMeasureUnit.Ones

        //统计图控件ChartControl的横轴滚动条用法
        //https://blog.csdn.net/jiangmufeng/java/article/details/54615932

        //1)X轴滚动条启用属性EnableAxisXScrolling  ，
        //((DevExpress.XtraCharts.XYDiagram)(chart1.Diagram)).EnableAxisXScrolling = true;//启用横轴滚动条
        //2）可见数据范围，VisualRange
        //((DevExpress.XtraCharts.XYDiagram)(chartControl1.Diagram)).AxisX.VisualRange.SetMinMaxValues(minValue, maxValue);
        //这一步是最关键的，要让可见范围小于整个数据范围，比如说整个图表一共有8条数据，分别为

        //那么数据范围WholeRange应该是（0,6），那么在设置可见数据范围时，应该使maxValue小于6或者使minValue大于0。否则即使启用了滚动轴滚动轴也不会显示。
        //            ((DevExpress.XtraCharts.XYDiagram)(chartControl1.Diagram)).AxisX.VisualRange.SetMinMaxValues(0, 5);
        //还有一点就是设置minValue,maxValue的数据类型应该与X轴的数据类型一致，否者也无法显示。

        //3）数据范围WholeRange
        //((DevExpress.XtraCharts.XYDiagram)(chart1.Diagram)).AxisX.WholeRange.Auto = true;

        #endregion

        ViewType viewType;

        public frmMES_Lab_ChartControl()
        {
            InitializeComponent();
            
        }
        private void frmMES_Lab_ChartControl_Resize(object sender, EventArgs e)
        {
            splitContainerControl1.SplitterPosition = this.Height - 150;
            splitContainerControl2.SplitterPosition = (this.Height - 150) / 2;
            splitContainerControl3.SplitterPosition = this.Width / 2;
            splitContainerControl4.SplitterPosition = this.Width / 2;
        }

        private void frmMES_Lab_ChartControl_Load(object sender, EventArgs e)
        {
            try { base.InitButtons(); } catch { }//初始化标准功能，因要应用于RibbonForm，所以加入异常处理
        }

        private void sbtnView_Click(object sender, EventArgs e)
        {
            //如果只有一个Series，用以下代码：
            //chartControl1.Series[0].Points.Clear();
            chartControl1.Series.Clear();
            try
            {
                ((XYDiagram)chartControl1.Diagram).SecondaryAxesY.Clear();//清空之前的右侧坐标, 可以有多个坐标轴
            }
            catch
            {

            }

            //如果有多个Series，用以下代码
            foreach (var series in chartControl1.Series)
            {
                //series.Points.Clear();
            }


            DataTable dt = CreateData();
            gridControl1.DataSource = dt;
            chartControl1.DataSource = dt;

            CreateChart(dt);
        }

        private void comboBoxEdit1_SelectedIndexChanged(object sender, EventArgs e)
        {
            string sql = "";
            sql = @"SELECT * FROM Test_Sample_ChartControl
WHERE CHART_NAME LIKE '%" + comboBoxEdit1.Text + @"%' AND REMARK='OK'
ORDER BY CHART_NAME";

            DataTable dt = null;
            dt = Lamex.Base.BaseBuildSql.GetDataTableBySql(sql);

            //手工添加ComboBoxEdit的数据源 
            comboBoxEdit2.Properties.Items.Clear();
            //comboBoxEdit2.Properties.Items.Add("");

            foreach (DataRow dr in dt.Rows)
            {
                comboBoxEdit2.Properties.Items.Add(dr[0].ToString().Trim());
            }
            comboBoxEdit2.Text = "";
        }

        /// <summary>
        /// 准备数据内容
        /// </summary>
        /// <returns></returns>
        private DataTable CreateData()
        {
            DataTable dt = new DataTable();
            dt.Columns.Add(new DataColumn("类型"));
            dt.Columns.Add(new DataColumn("2005-1月", typeof(decimal)));
            dt.Columns.Add(new DataColumn("2005-2月", typeof(decimal)));
            dt.Columns.Add(new DataColumn("2005-3月", typeof(decimal)));
            dt.Columns.Add(new DataColumn("2005-4月", typeof(decimal)));
            //dt.Columns.Add(new DataColumn("2005-5月", typeof(decimal)));
            //dt.Columns.Add(new DataColumn("2005-6月", typeof(decimal)));

            dt.Rows.Add(new object[] { "员工人数", 437, 437, 414, 397 });
            dt.Rows.Add(new object[] { "人均月薪", 3964, 3961, 3979, 3974 });
            dt.Rows.Add(new object[] { "成本TEU", 3104, 1339, 3595.8, 3154.5 });

            //dt.Rows.Add(new object[] { "员工人数", 437, 437, 414, 397, 387, 378 });
            //dt.Rows.Add(new object[] { "人均月薪", 3964, 3961, 3979, 3974, 3967, 3972 });
            //dt.Rows.Add(new object[] { "成本TEU", 3104, 1339, 3595.8, 3154.5, 2499.8, 3026 });
            //dt.Rows.Add(new object[] { "人均生产率", 7.1, 3.06, 8.69, 7.95, 6.46, 8.01 });
            //dt.Rows.Add(new object[] { "占2005年3月人数比例", 1.06, 1.06, 1, 0.96, 0.93, 0.91 });

            return dt;
        }

        private void CreateChart(DataTable dt)
        {
            #region Series

            //创建几个图形的对象
            //ViewType viewType = ViewType.Line;
            //ViewType viewType = ViewType.Area;
            getChartType();

            Series series1 = CreateSeries("员工人数", viewType, dt, 0);
            Series series2 = CreateSeries("人均月薪", viewType, dt, 1);
            Series series3 = CreateSeries("成本TEU", viewType, dt, 2);
            //Series series4 = CreateSeries("人均生产率", viewType, dt, 3);
            //Series series5 = CreateSeries("占2005年3月人数比例", viewType, dt, 4);

            //Series series1 = CreateSeries("员工人数", ViewType.Line, dt, 0);
            //Series series2 = CreateSeries("人均月薪", ViewType.Line, dt, 1);
            //Series series3 = CreateSeries("成本TEU", ViewType.Line, dt, 2);
            //Series series4 = CreateSeries("人均生产率", ViewType.Line, dt, 3);
            //Series series5 = CreateSeries("占2005年3月人数比例", ViewType.Line, dt, 4);

            #endregion

            //List<Series> list = new List<Series>() { series1, series2, series3, series4, series5 };
            List<Series> list = new List<Series>() { series1, series2, series3 };

            chartControl1.Series.AddRange(list.ToArray());
            //chartControl1.Legend.Visible = false;
            //chartControl1.SeriesTemplate.LabelsVisibility = DefaultBoolean.True;

            List<Color> colorList = new List<Color>();
            colorList.Add(Color.Red);
            colorList.Add(Color.Blue);
            colorList.Add(Color.Green);
            //colorList.Add(Color.Yellow);
            //colorList.Add(Color.Black);

            for (int i = 0; i < list.Count; i++)
            {
                list[i].View.Color = colorList[i];
                CreateAxisY(list[i]);
            }
        }

        //获取图形类别
        private void getChartType()
        {
            switch (comboBoxEdit2.Text)
            {
                case "Bar":
                    viewType = ViewType.Bar;
                    break;
                case "StackedBar":
                    viewType = ViewType.StackedBar;
                    break;
                case "FullStackedBar":
                    viewType = ViewType.FullStackedBar;
                    break;
                case "SideBySideStackedBar":
                    viewType = ViewType.SideBySideStackedBar;
                    break;
                case "SideBySideFullStackedBar":
                    viewType = ViewType.SideBySideFullStackedBar;
                    break;
                case "Pie":
                    viewType = ViewType.Pie;
                    break;
                case "Doughnut":
                    viewType = ViewType.Doughnut;
                    break;
                case "NestedDoughnut":
                    viewType = ViewType.NestedDoughnut;
                    break;
                case "Funnel":
                    viewType = ViewType.Funnel;
                    break;
                case "Point":
                    viewType = ViewType.Point;
                    break;
                case "Bubble":
                    viewType = ViewType.Bubble;
                    break;
                case "Line":
                    viewType = ViewType.Line;
                    break;
                case "StackedLine":
                    viewType = ViewType.StackedLine;
                    break;
                case "FullStackedLine":
                    viewType = ViewType.FullStackedLine;
                    break;
                case "StepLine":
                    viewType = ViewType.StepLine;
                    break;
                case "Spline":
                    viewType = ViewType.Spline;
                    break;
                case "ScatterLine":
                    viewType = ViewType.ScatterLine;
                    break;
                case "SwiftPlot":
                    viewType = ViewType.SwiftPlot;
                    break;
                case "Area":
                    viewType = ViewType.Area;
                    break;
                case "StepArea":
                    viewType = ViewType.StepArea;
                    break;
                case "SplineArea":
                    viewType = ViewType.SplineArea;
                    break;
                case "StackedArea":
                    viewType = ViewType.StackedArea;
                    break;
                case "StackedStepArea":
                    viewType = ViewType.StackedStepArea;
                    break;
                case "StackedSplineArea":
                    viewType = ViewType.StackedSplineArea;
                    break;
                case "FullStackedArea":
                    viewType = ViewType.FullStackedArea;
                    break;
                case "FullStackedSplineArea":
                    viewType = ViewType.FullStackedSplineArea;
                    break;
                case "FullStackedStepArea":
                    viewType = ViewType.FullStackedStepArea;
                    break;
                case "RangeArea":
                    viewType = ViewType.RangeArea;
                    break;
                case "Stock":
                    viewType = ViewType.Stock;
                    break;
                case "CandleStick":
                    viewType = ViewType.CandleStick;
                    break;
                case "SideBySideRangeBar":
                    viewType = ViewType.SideBySideRangeBar;
                    break;
                case "RangeBar":
                    viewType = ViewType.RangeBar;
                    break;
                case "SideBySideGantt":
                    viewType = ViewType.SideBySideGantt;
                    break;
                case "Gantt":
                    viewType = ViewType.Gantt;
                    break;
                case "PolarPoint":
                    viewType = ViewType.PolarPoint;
                    break;
                case "PolarLine":
                    viewType = ViewType.PolarLine;
                    break;
                case "ScatterPolarLine":
                    viewType = ViewType.ScatterPolarLine;
                    break;
                case "PolarArea":
                    viewType = ViewType.PolarArea;
                    break;
                case "PolarRangeArea":
                    viewType = ViewType.PolarRangeArea;
                    break;
                case "RadarPoint":
                    viewType = ViewType.RadarPoint;
                    break;
                case "RadarLine":
                    viewType = ViewType.RadarLine;
                    break;
                case "ScatterRadarLine":
                    viewType = ViewType.ScatterRadarLine;
                    break;
                case "RadarArea":
                    viewType = ViewType.RadarArea;
                    break;
                case "RadarRangeArea":
                    viewType = ViewType.RadarRangeArea;
                    break;
                case "Bar3D":
                    viewType = ViewType.Bar3D;
                    break;
                case "StackedBar3D":
                    viewType = ViewType.StackedBar3D;
                    break;
                case "FullStackedBar3D":
                    viewType = ViewType.FullStackedBar3D;
                    break;
                case "ManhattanBar":
                    viewType = ViewType.ManhattanBar;
                    break;
                case "SideBySideStackedBar3D":
                    viewType = ViewType.SideBySideStackedBar3D;
                    break;
                case "SideBySideFullStackedBar3D":
                    viewType = ViewType.SideBySideFullStackedBar3D;
                    break;
                case "Pie3D":
                    viewType = ViewType.Pie3D;
                    break;
                case "Doughnut3D":
                    viewType = ViewType.Doughnut3D;
                    break;
                case "Funnel3D":
                    viewType = ViewType.Funnel3D;
                    break;
                case "Line3D":
                    viewType = ViewType.Line3D;
                    break;
                case "StackedLine3D":
                    viewType = ViewType.StackedLine3D;
                    break;
                case "FullStackedLine3D":
                    viewType = ViewType.FullStackedLine3D;
                    break;
                case "StepLine3D":
                    viewType = ViewType.StepLine3D;
                    break;
                case "Area3D":
                    viewType = ViewType.Area3D;
                    break;
                case "StackedArea3D":
                    viewType = ViewType.StackedArea3D;
                    break;
                case "FullStackedArea3D":
                    viewType = ViewType.FullStackedArea3D;
                    break;
                case "StepArea3D":
                    viewType = ViewType.StepArea3D;
                    break;
                case "Spline3D":
                    viewType = ViewType.Spline3D;
                    break;
                case "SplineArea3D":
                    viewType = ViewType.SplineArea3D;
                    break;
                case "StackedSplineArea3D":
                    viewType = ViewType.StackedSplineArea3D;
                    break;
                case "FullStackedSplineArea3D":
                    viewType = ViewType.FullStackedSplineArea3D;
                    break;
                case "RangeArea3D":
                    viewType = ViewType.RangeArea3D;
                    break;
                //case "BoxPlot ":
                //    viewType = ViewType.BoxPlot;
                //    break;
                //case "Waterfall ":
                //    viewType = ViewType.Waterfall;
                //    break;
                default:
                    //viewType = "";
                    break;
            }
        }

        /// <summary>
        /// 根据数据创建一个图形展现
        /// </summary>
        /// <param name="caption">图形标题</param>
        /// <param name="viewType">图形类型</param>
        /// <param name="dt">数据DataTable</param>
        /// <param name="rowIndex">图形数据的行序号</param>
        /// <returns></returns>
        private Series CreateSeries(string caption, ViewType viewType, DataTable dt, int rowIndex)
        {
            Series series = new Series(caption, viewType);
            for (int i = 1; i < dt.Columns.Count; i++)
            {
                string argument = dt.Columns[i].ColumnName;//参数名称
                decimal value = (decimal)dt.Rows[rowIndex][i];//参数值
                series.Points.Add(new SeriesPoint(argument, value));
            }

            //必须设置ArgumentScaleType的类型，否则显示会转换为日期格式，导致不是希望的格式显示
            //也就是说，显示字符串的参数，必须设置类型为ScaleType.Qualitative
            series.ArgumentScaleType = ScaleType.Qualitative;
            series.LabelsVisibility = DevExpress.Utils.DefaultBoolean.True;//显示标注标签

            return series;
        }

        /// <summary>
        /// 创建图表的第二坐标系
        /// </summary>
        /// <param name="series">Series对象</param>
        /// <returns></returns>
        private SecondaryAxisY CreateAxisY(Series series)
        {
            SecondaryAxisY myAxis = new SecondaryAxisY(series.Name);
            ((XYDiagram)chartControl1.Diagram).SecondaryAxesY.Add(myAxis);

            #region 设定系列视图类型

            switch (comboBoxEdit2.Text)
            {
                //case "Area3D":
                //    ((Area3DSeriesView)series.View).AxisY = myAxis;
                //    break;
                case "Area":
                    ((AreaSeriesView)series.View).AxisY = myAxis;
                    break;
                //case "BoxPlot":
                //    ((BoxPlotSeriesView)series.View).AxisY = myAxis;
                //    break;
                case "Bubble"://???
                    ((BubbleSeriesView)series.View).AxisY = myAxis;
                    break;
                case "CandleStick"://???
                    ((CandleStickSeriesView)series.View).AxisY = myAxis;
                    break;
                //case "Doughnut3D	":
                //    ((Doughnut3DSeriesView)series.View).AxisY = myAxis;
                //    break;
                //case "Doughnut":
                //    ((DoughnutSeriesView)series.View).AxisY = myAxis;
                //    break;
                //case "FullStackedArea3D":
                //    ((FullStackedArea3DSeriesView)series.View).AxisY = myAxis;
                //    break;
                case "FullStackedArea":
                    ((FullStackedAreaSeriesView)series.View).AxisY = myAxis;
                    break;
                //case "FullStackedBar3D":
                //    ((FullStackedBar3DSeriesView)series.View).AxisY = myAxis;
                //    break;
                case "FullStackedBar":
                    ((FullStackedBarSeriesView)series.View).AxisY = myAxis;
                    break;
                //case "FullStackedLine3D":
                //    (FullStackedLine3DSeriesView)series.View).AxisY = myAxis;
                //    break;
                case "FullStackedLine":
                    ((FullStackedLineSeriesView)series.View).AxisY = myAxis;
                    break;
                //case "FullStackedSplineArea3D":
                //    ((FullStackedSplineArea3DSeriesView)series.View).AxisY = myAxis;
                //    break;
                case "FullStackedSplineArea":
                    ((FullStackedSplineAreaSeriesView)series.View).AxisY = myAxis;
                    break;
                case "FullStackedStepArea":
                    ((FullStackedStepAreaSeriesView)series.View).AxisY = myAxis;
                    break;
                //case "Funnel3D":
                //    ((Funnel3DSeriesView)series.View).AxisY = myAxis;
                //    break;
                //case "Funnel":
                //    ((FunnelSeriesView)series.View).AxisY = myAxis;
                //    break;
                case "Gantt"://???
                    ((GanttSeriesView)series.View).AxisY = myAxis;
                    break;
                //case "Line3D":
                //    ((Line3DSeriesView)series.View).AxisY = myAxis;
                //    break;
                case "Line":
                    ((LineSeriesView)series.View).AxisY = myAxis;
                    break;
                //case "ManhattanBar":
                //    ((ManhattanBarSeriesView)series.View).AxisY = myAxis;
                //    break;
                //case "NestedDoughnut":
                //    ((NestedDoughnutSeriesView)series.View).AxisY = myAxis;
                //    break;
                //case "Pie3D":
                //    ((Pie3DSeriesView)series.View).AxisY = myAxis;
                //    break;
                //case "Pie":
                //    ((PieSeriesView)series.View).AxisY = myAxis;
                //    break;
                case "Point":
                    ((PointSeriesView)series.View).AxisY = myAxis;
                    break;
                //case "PolarArea":
                //    ((PolarAreaSeriesView)series.View).AxisY = myAxis;
                //    break;
                //case "PolarLine":
                //    ((PolarLineSeriesView)series.View).AxisY = myAxis;
                //    break;
                //case "PolarPoint":
                //    ((PolarPointSeriesView)series.View).AxisY = myAxis;
                //    break;
                //case "PolarRangeArea":
                //    ((PolarRangeAreaSeriesView)series.View).AxisY = myAxis;
                //    break;
                //case "RadarArea":
                //    ((RadarAreaSeriesView)series.View).AxisY = myAxis;
                //    break;
                //case "RadarLine":
                //    ((RadarLineSeriesView)series.View).AxisY = myAxis;
                //    break;
                //case "RadarPoint":
                //    ((RadarPointSeriesView)series.View).AxisY = myAxis;
                //    break;
                //case "RadarRangeArea":
                //    ((RadarRangeAreaSeriesView)series.View).AxisY = myAxis;
                //    break;
                //case "RangeArea3D":
                //    ((RangeArea3DSeriesView)series.View).AxisY = myAxis;
                //    break;
                case "RangeArea"://???
                    ((RangeAreaSeriesView)series.View).AxisY = myAxis;
                    break;
                case "RangeBar"://???
                    ((RangeBarSeriesView)series.View).AxisY = myAxis;
                    break;
                case "ScatterLine":
                    ((ScatterLineSeriesView)series.View).AxisY = myAxis;
                    break;
                //case "ScatterPolarLine":
                //    ((ScatterPolarLineSeriesView)series.View).AxisY = myAxis;
                //    break;
                //case "ScatterRadarLine	":
                //    ((ScatterRadarLineSeriesView)series.View).AxisY = myAxis;
                //    break;
                //case "Bar3D":
                //    ((SideBySideBar3DSeriesView)series.View).AxisY = myAxis;
                //    break;
                case "Bar":
                    ((SideBySideBarSeriesView)series.View).AxisY = myAxis;
                    break;
                //case "SideBySideFullStackedBar3D":
                //    ((SideBySideFullStackedBar3DSeriesView)series.View).AxisY = myAxis;
                //    break;
                case "SideBySideFullStackedBar":
                    ((SideBySideFullStackedBarSeriesView)series.View).AxisY = myAxis;
                    break;
                case "SideBySideGantt"://???
                    ((SideBySideGanttSeriesView)series.View).AxisY = myAxis;
                    break;
                case "SideBySideRangeBar"://???
                    ((SideBySideRangeBarSeriesView)series.View).AxisY = myAxis;
                    break;
                //case "SideBySideStackedBar3D":
                //    ((SideBySideStackedBar3DSeriesView)series.View).AxisY = myAxis;
                //    break;
                case "SideBySideStackedBar":
                    ((SideBySideStackedBarSeriesView)series.View).AxisY = myAxis;
                    break;
                //case "Spline3D":break;
                //case "SplineArea3D":
                //    ((Spline3DSeriesView)series.View).AxisY = myAxis;
                //    break;
                case "SplineArea":
                    ((SplineAreaSeriesView)series.View).AxisY = myAxis;
                    break;
                case "Spline":
                    ((SplineSeriesView)series.View).AxisY = myAxis;
                    break;
                //case "StackedArea3D":
                //    ((StackedArea3DSeriesView)series.View).AxisY = myAxis;
                //    break;
                case "StackedArea":
                    ((StackedAreaSeriesView)series.View).AxisY = myAxis;
                    break;
                //case "StackedBar3D":
                //    ((StackedBar3DSeriesView)series.View).AxisY = myAxis;
                //    break;
                case "StackedBar":
                    ((StackedBarSeriesView)series.View).AxisY = myAxis;
                    break;
                //case "StackedLine3D":
                //    ((StackedLine3DSeriesView)series.View).AxisY = myAxis;
                //    break;
                case "StackedLine":
                    ((StackedLineSeriesView)series.View).AxisY = myAxis;
                    break;
                //case "StackedSplineArea3D":
                //    ((StackedSplineArea3DSeriesView)series.View).AxisY = myAxis;
                //    break;
                case "StackedStepArea": break;
                case "StackedSplineArea"://???
                    ((StackedStepAreaSeriesView)series.View).AxisY = myAxis;
                    break;
                //case "StepArea3D":
                //    ((StepArea3DSeriesView)series.View).AxisY = myAxis;
                //    break;
                case "StepArea":
                    ((StepAreaSeriesView)series.View).AxisY = myAxis;
                    break;
                //case "StepLine3D":
                //    ((StepLine3DSeriesView)series.View).AxisY = myAxis;
                //    break;
                case "StepLine":
                    ((StepLineSeriesView)series.View).AxisY = myAxis;
                    break;
                case "Stock"://???
                    ((StockSeriesView)series.View).AxisY = myAxis;
                    break;
                //case "SwiftPlot":
                //    ((SwiftPlotSeriesView)series.View).AxisY = myAxis;
                //    break;
                //case "Waterfall":
                //    ((WaterfallSeriesView)series.View).AxisY = myAxis;
                //    break;

            }

            #endregion

            //((LineSeriesView)series.View).AxisY = myAxis;
            myAxis.Title.Text = series.Name;
            myAxis.Title.Alignment = StringAlignment.Far; //顶部对齐
            myAxis.Title.Visible = true; //显示标题
            myAxis.Title.Font = new Font("宋体", 9.0f);

            Color color = series.View.Color;//设置坐标的颜色和图表线条颜色一致

            myAxis.Title.TextColor = color;
            myAxis.Label.TextColor = color;
            myAxis.Color = color;

            return myAxis;
        }

        //打印也可以使用下面的代码，效果差不多，但是定制性比较强一点。
        private void btnPrint_Click(object sender, EventArgs e)
        {
            //this.chartControl1.ShowPrintPreview(DevExpress.XtraCharts.Printing.PrintSizeMode.Zoom);
            DevExpress.XtraPrintingLinks.CompositeLink compositeLink = new DevExpress.XtraPrintingLinks.CompositeLink();
            DevExpress.XtraPrinting.PrintingSystem ps = new DevExpress.XtraPrinting.PrintingSystem();

            compositeLink.PrintingSystem = ps;
            compositeLink.Landscape = true;
            compositeLink.PaperKind = System.Drawing.Printing.PaperKind.A4;

            DevExpress.XtraPrinting.PrintableComponentLink link = new DevExpress.XtraPrinting.PrintableComponentLink(ps);
            ps.PageSettings.Landscape = true;
            link.Component = this.chartControl1;
            compositeLink.Links.Add(link);

            link.CreateDocument();  //建立文档
            ps.PreviewFormEx.Show();//进行预览
        }

        #region 标准功能

        public override void DoView(IButtonInfo sender)
        {
            sbtnView_Click(null, null);
            base.DoView(sender);
        }

        public override void DoPrint(IButtonInfo sender)
        {
            chartControl1.ShowPrintPreview(DevExpress.XtraCharts.Printing.PrintSizeMode.Zoom);
            base.DoPrint(sender);
        }

        #endregion

    }
}